/**
 * 洛克人攻击 
 */
var shootType = 1;//武器类型
var shootTime = 0.15;//射击速度
var shootNum = 3;//子弹个数
var xshoot = require("xshoot")
cc.Class({
    extends: cc.Component,

    properties: {
        player: cc.Node,
        main: cc.Node,
    },

    onLoad: function () {
        this._shootSpeedTime = 0;
        this._shootNum = 0;
        cc.director.on(GameEvent.PLAYER_EVENT, this.onPlayEvent, this)
    },


    changeShootState: function (value) {
        // value *= this.dt;
        if (this.player && value != 0) {

            var com = this.player.getComponent("player");
            if (this._shootNum >= shootNum) {
                this._shootNum = 0
                this._shootSpeedTime = 0;
            } else {
                com.playAn(PlayerStates.PlayerAnimaEnemu.XSHOOT)
            }

        }
    },

    changeXAttack: function (attackType) {
        // value *= this.dt;
        if (this.player && attackType) {

            var com = this.player.getComponent("player");
            com.playAn(attackType)
        }
    },



    shootEnd: function (parm) {
        cc.log("射击结束了");
    },

    update: function (dt) {
        if (InputControl.getControl(GameEvent.KEY.C) && PlayerStates.is(PlayerStates.PlayerStatesEnum.PlayerShoot)) {
            if (this._shootSpeedTime > shootTime) {
                this._shootSpeedTime -= shootTime;
                this._shootNum++;
                this.changeShootState(1);
            }
            this._shootSpeedTime += dt ;
        } else if (InputControl.getControl(GameEvent.KEY.X) && PlayerStates.is( PlayerStates.PlayerStatesEnum.PlayerXAttack)) {//x特殊攻击 
            var isGround = this.player.getComponent("player").isGround();
            if (isGround) {
                this.changeXAttack("x_sword")
            }else if (this.player.getComponent("player").getSpace()){
                this.changeXAttack("x_jumpSwrod");
            }
        } else {
            this._shootNum = 0
            this._shootSpeedTime = 0
        }
    },




    onPlayEvent: function (eventData) {
        let state = PlayerStates.getCurState();
        // if (state === PlayerStates.PlayerStatesEnum.PlayerShoot) {

        // } else if (
    },

    gaShoot: function (shootVo) {//射击
        var m = new xshoot();//后面再用子弹管理器
        m.shoot();

    },
});
